<?

	/**

		Index of 'Common Administration Tool by Jay Casee'

	*/



	/*

		To Do List

			본사 ERD 비교 분석
			접속 로그 생성
			쿼리 수행 로그 생성
			쿼리 수행 로그 설정
			보기 모드
			엑셀 추출
			1:n FK 테이블 생성 추출
			파일 FTP 업로드 외 기타
			국가 EN → US
			언어 KR → KO, VN → VI

	*/



	/*

		Work Process

			1. Design the database scheme.
			2. Configurate 'JC_01_configuration.php' file.



		Data Relationship Scheme Policy

			1:1 limited	: This has a 'option' on a 'varchar' type field.
			1:n limited	: This has a 'option' on a 'text' type field with '\r\n' separators.
			1:1			: This has a 'FKT' & a 'FKF' on a 'int' type field.
			1:n			: This has a 'FKT' & a 'FKF' on a 'text' type field with '\r\n' separators.

			The 'limited' means a case which has limited options to be related. Actually this is not a 'data relationship scheme'.
			The 'option', 'FKT' and 'FKF' is described at 'Field Comment', below.



		Field Comment

			priority	: integer; DESC;						This means the priority order of the table. This must be on the 'key' (PK) field, only.

			AS			: Authority Select;						If this is on the PK field, this means the authority of the table.
			AIUD		: Authority Input, Update and Delete;	If this is on the PK field, this means the authority of the table.

			FKT			: Foreign Key Table;					This helps not to spend a time to make a join query.
			FKF			: Foreign Key Field;					This helps not to spend a time to make a join query.

			option		: "option: item 1[, item 2][, ...];";	This changes a 'varchar' or 'text' type field to a 'select' type tag.
			multiple	: boolean
			default		: text;									This is a default value of every type tag.
			size		: integer unsigned						This is a horizontal size of a 'input' or 'textarea' type tag

			unit		: "USD", "kg", "cm" or whatever.		This is a unit of a field.
			comment		: text									This is a comment of a field.

			JC uses a field comment as a configuration.



		Common Table Field

			key			: int(10) unsigned; auto_increment	 	 	 	 	 	 	

			note		: text; null
			log			: text
			insert		: datetime
			update		: datetime; null		 	 	 	 	 	 	
			delete		: datetime; null		 	 	 	 	 	 	



		account Table Field

			identifier	: varchar(16)
			password	: varchar(16)
			authority	: varchar(16); "option: administrator, observer;"
			name		: varchar(64)

			mail		: text; null
			phone		: text; null
			address		: text; null
			description	: text; null



		File Table Field

			host		: text; null;				"option: default, account, photo, music, video; multiple: true;"
			name		: varchar(64); null
			URL			: text; null
			protocol	: varchar(4);				"option: HTTP, FTP;"
			type		: varchar(16)
			size		: int(10) unsigned;			"unit: byte;"
			bitrate		: int(10) unsigned;	null;	"unit: bit/s;"
			width		: int(10) unsigned;	null;	"unit: pixel;"
			height		: int(10) unsigned;	null;	"unit: pixel;"
			duration	: int(10) unsigned;	null;	"unit: second;"
			description	: text;				null

			JC supports multi file host structure but this is not simple about its configuration.
			The 'host' and 'name' fields are being for the '$JC_host' variable in 'JC_01_configuration.php' file.
			The 'URL' field is being for a simple use of an external file.
			JC recomends to use the 'host' and 'name' fields and in this case the 'URL' field will be null.

			But those functions have not finished to make... - _ - ;;;
			You can find many uncoded parts about this.
			It is still conceptual.

			http://www.ffmpeg.org/
			http://ffmpeg-php.sourceforge.net/
			http://www.apachefriends.org/f/viewtopic.php?f=16&t=32688



		FIle Upload Process

			1. Upload a file to 'JC_90_file_temporary' folder by FTP.
			2. Insert a record to 'file' table. At this process you can find the file that you've uploaded at the previous step.



		Log Item

			Visit		: datetime; IP Address; account.key; URL
			Query		: datetime; IP Address; account.key; Query; Query Error Message

	*/



	session_start( );

	include_once( "JC_01_configuration.php"	);
	include_once( "JC_02_function.php"		);

?>



<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

	<head>

		<title>JC - <?= $JC_database_database ?></title>

		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

		<? include_once( "JC_03_JS.php"	); ?>
		<? include_once( "JC_04_CSS.php"	); ?>

	</head>

	<body>

		<div id="JC" class="JC">

			<?

				////
				///
				//	MySQL

					$JC_MySQL = new mysqli( $JC_database_host, $JC_database_account, $JC_database_password, $JC_database_database );
					$JC_MySQL -> query( "SET NAMES 'UTF8'" );



				////
				///
				//	Query Log In & Out

					if( $_REQUEST[ "JC_query" ] == "LI" ) JC_LI( ); // Log In
					if( $_REQUEST[ "JC_query" ] == "LO" ) JC_LO( ); // Log Out



				if( ! $_SESSION[ "JC_account_authority" ] ) {



					////
					///
					//	Authority

						include_once( "JC_10_authority.php" );



				} else { // if( ! $_SESSION[ "JC_account_authority" ] )



					////
					///
					//	Scheme

						if( ! $_SESSION[ "JC_scheme" ] ) JC_scheme( );



					if( ! $_REQUEST[ "JC_query" ] ) {



						////
						///
						//	account Interface

							include_once( "JC_11_menu.php" );

							if( $_REQUEST[ "JC_table" ] ) {

								echo "<b>" . ucwords( $_REQUEST[ "JC_table" ] ) . "</b>" . ( $_SESSION[ "JC_scheme" ][ $_REQUEST[ "JC_table" ] ][ "comment" ] ? "<span> : " . $_SESSION[ "JC_scheme" ][ $_REQUEST[ "JC_table" ] ][ "comment" ] . "</span>" : "" ) . "<br /><hr />";

								if( $_REQUEST[ "JC_mode" ] == "select"										) include_once( "JC_13_select.php" );
								if( $_REQUEST[ "JC_mode" ] == "update" || empty( $_REQUEST[ "JC_mode" ] )	) include_once( "JC_14_update.php" );
								if( $_REQUEST[ "JC_mode" ] != "insert"										) include_once( "JC_12_filter.php" );
								if( $_REQUEST[ "JC_mode" ] == "insert" || empty( $_REQUEST[ "JC_mode" ] )	) include_once( "JC_15_insert.php" );;

							} else {

								if( $_REQUEST[ "JC_file" ] ) {

									include_once( "JC_" . $_REQUEST[ "JC_file" ] . ".php"	);

								} else {

									include_once( "JC_19_summary.php"	);
									include_once( "JC_05_MySQL.php"		);

								}

							}



						////
						///
						//	Asynchronous

							echo "<hr /><iframe id='JC_asynchronous'></iframe>";



					} else { // if( ! $_REQUEST[ "JC_query" ] )



						////
						///
						//	Session

							if( $_REQUEST[ "JC_query" ] == "session" ) JC_session ( );



						////
						///
						//	Query Insert, Update & Delete

							if( $_REQUEST[ "JC_query" ] == "insert" ) JC_insert( );
							if( $_REQUEST[ "JC_query" ] == "update" ) JC_update( );
							if( $_REQUEST[ "JC_query" ] == "delete" ) JC_delete( );



					} // if( ! $_REQUEST[ "JC_query" ] )



				} // if( ! $_SESSION[ "JC_account_authority" ] )



				////
				///
				//	MySQL

					$JC_MySQL -> close( );

			?>

			<pre><? if( $_REQUEST[ "JC_debug" ] && $_SESSION[ "JC_account_authority" ] ) print_r( $GLOBALS ); ?></pre>

		</div>

	</body>

</html>

<?

	////
	///
	//	Inspection

		//JC_inspection( );

?>
